var trActive = null;

function edit(div, questionID)
{
	var trActive = div.parentNode;
	while (trActive.nodeName.toLowerCase() != 'tr') trActive = trActive.parentNode;
	server_getElementById('hdArg').value = questionID;
	showModalPopup('editform');
	
	var question = div.getElementsByTagName('span');
	for (var i=0; i<question.length; i++)
		if (question[i].className == 'question')
				{ question = question[i].innerHTML; break; }
				
	if (question) question = trimstr(question);
	
	server_getElementById('txtQuestion').value = question;
}

function checkthis(chk)
{
	var tr = chk.parentNode;
	while (tr.nodeName.toLowerCase() != 'tr') tr = tr.parentNode;
	if (chk.checked)
		tr.className = 'item selected';
	else
		tr.className = '';
}
function DeleteOne(a, questionID)
{
	var tr = a.parentNode;
	while (tr.nodeName.toLowerCase() != 'tr') tr = tr.parentNode;
	tr.className = 'item selected';
	tr.getElementsByTagName('input')[0].checked = true;
	server_getElementById('hdArg').value = questionID;
	__doPostBack(server_getElementById('btnDeleteOne').name,'');
	setTimeout('removeactiverow()', 100);
}
function traloi_init()
{
	if (typeof(Sys) != 'undefined')
	{
		Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(traloi_BeginRequestHandler);
		Sys.WebForms.PageRequestManager.getInstance().add_endRequest(traloi_EndRequestHandler);
	}
	// neu khong co ban ghi nao thi reload sau 30second
	if (server_getElementById('grdQuestion').getElementsByTagName('tr').length <= 1) setTimeout('window.location.href = window.location.href', 30000);
	document.getElementById('idContentIDtab_ctl16_ctl02_txtAnswer').style.height = '233px';
}

ie ?  attachEvent('onload', traloi_init) : addEventListener('load', traloi_init, false);

function redirecQuestion(cbo, questionID)
{
	server_getElementById('hdArg').value = questionID + ',' + cbo.options[cbo.selectedIndex].value;
	
	var tr = cbo.parentNode.parentNode;
	tr.className = 'item active';
	tr.getElementsByTagName('input')[0].checked = true;
	
	__doPostBack(server_getElementById('btnRedirectQuestion').name,'');
	
	setTimeout('removeactiverow()', 100);
}

function traloi_BeginRequestHandler(sender, args)
{
//	var chk, chks = server_getElementById('grdQuestion').getElementsByTagName('input');
//	var i = 0, count = chks.length;
//	var tr;
//	for (i=1; i<count; i++)
//	{
//		chk = chks[i];
//		if (chk.type == 'checkbox' && chk.id.indexOf('chkFirstColumn') >= 0 && chk.checked)
//		{
//			tr = chk.parentNode;
//			while (tr.nodeName.toLowerCase() != 'tr') tr = tr.parentNode;
//			tr.className = 'item active';
//		}
//	}
}
function traloi_EndRequestHandler(sender, args)
{
	removeactiverow();
}
function removeactiverow()
{
	var tr, trs = server_getElementById('grdQuestion').getElementsByTagName('tr');
	var i=0, count = trs.length;
	var arr = new Array();
	for (i=1; i<count; i++)
	{
		tr = trs[i];
		chks = tr.getElementsByTagName('input');
		if (chks.length > 0 && chks[0].checked) arr.push(tr);
	}
	count = arr.length;
	var tbody;
	if (count>0) tbody = arr[0].parentNode;
	for (i=0; i<count; i++)
	{
		tr = arr.pop();
		tbody.removeChild(tr);
	}
}
